<?php

namespace Model\SchoolBundle\Controller;

use Model\SchoolBundle\Setting\SchoolSetting;
use Model\SchoolCategoryBundle\Model\SchoolCategoryModel;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

use Symfony\Component\HttpFoundation\Request;
use Base\BaseController;
use Model\SchoolBundle\Entity\School as Entity;

/**
 * @route("/admin/")
 */
class SchoolAdminController extends BaseController
{

    /**
     * @route("School/add",name="SchoolPreAdd")
     */
    public function add()
    {
        die("不建议管理员直接管理学校信息");
        //通用代码
        $this->setSetting(new SchoolSetting($this->getDoctrine()->getManager()));
        return $this->comAdd();
    }

    /**
     * @route("School/add/do",name="SchoolDoAdd")
     *
     * @Method({"GET", "POST"})
     */
    public function doAdd(Request $request)
    {
        die("不建议管理员直接管理学校信息");
        //私有代码
        $entity = new Entity();
        $entity->setAddTime(time());

        //通用代码
        $this->setSetting(new SchoolSetting($this->getDoctrine()->getManager()));
        return $this->comDoAdd($request,$entity);
    }

    /**
     * @route("School/edit/{id}",name="SchoolPreEdit")
     */
    public function edit(Entity $entity)
    {
        die("不建议管理员直接管理学校信息");
        $this->setSetting(new SchoolSetting($this->getDoctrine()->getManager()));
        return $this->comEdit($entity);
    }

    /**
     * @route("School/edit/{id}/do",name="SchoolDoEdit")
     *
     * @Method({"GET", "POST"})
     */
    public function doEdit(Request $request,Entity $entity)
    {
        die("不建议管理员直接管理学校信息");
        $this->setSetting(new SchoolSetting($this->getDoctrine()->getManager()));
        return $this->comDoEdit($request,$entity);
    }

    /**
     * @route("School",name="SchoolLists")
     */
    public function lists()
    {
        //私有部分
        $categoryModel = new SchoolCategoryModel($this->getDoctrine());
        $classes = $categoryModel->getAllSchoolCategoryTree();
        $tools = array("category"    => $classes,);

        //通用部分
        $this->setSetting(new SchoolSetting($this->getDoctrine()->getManager()));
        return $this->comLists($tools);
    }


    /**
     * @route("School/tools",name="SchoolTools")
     */
    public function tools(Request $request)
    {
        $this->setSetting(new SchoolSetting($this->getDoctrine()->getManager()));
        return $this->comTools($request);
    }

}
